#include "reflection_effect.h"

#include "graphics/cube_texture_gl.h"
#include "geometry/point.h"

namespace venus {
ReflectionEffect::ReflectionEffect(float reflection_factor)
    : reflection_factor_(reflection_factor) {
  Info("ReflectionEffect::ReflectionEffect");
  program_.Load("shaders/reflection.vp", "shaders/reflection.fp");
  program_.Link();
  eye_pos_var_ = program_.GetUniformVar("eye_pos");
  material_color_var_ = program_.GetUniformVar("material_color");
  env_map_var_ = program_.GetUniformVar("env_map");
  reflection_factor_var_ = program_.GetUniformVar("reflection_factor");
  CheckErrorsGL("ReflectionEffect::ReflectionEffect");
}
void ReflectionEffect::Begin() const {
  CheckErrorsGL("Reflectionion::Begin");
  program_.Begin();
  glUniform3fv(eye_pos_var_, 1, eye_pos_->ptr());
  glUniform4fv(material_color_var_, 1, material_color_->ptr());
  glUniform1i(env_map_var_, env_map_);
  glUniform1f(reflection_factor_var_, reflection_factor_);
  CheckErrorsGL("Reflectionion::End");
}
void ReflectionEffect::End() const {
  program_.End();
}
} // namespace venus
